$(function () {
    var tale = new $.tale();
    getinfo(1);
})
function getinfo(pagenum) {
    //页面加载完后，发出ajax请求
    $.post({
        xhrFields: {
            withCredentials: true
        },
        url: baseurl+api.logs+pagenum,
        success: function (res) {
            var s1 = "";
            var logList=res.data.logList;
            var pageinfo=res.data.pageinfo;
            for (var i = 0; i < logList.length; i++) {
                s1 += " <tr style='vertical-align: middle;text-align: center;'>\n" +
                    "                            <td>" + logList[i].id + "</td>\n" +
                    "                            <td>" + logList[i].action + "</td>\n" +
                    "                            <td>"+logList[i].status+ "</td>\n" +
                    "                            <td>"+logList[i].time+ "</td>\n" +
                    "                        </tr>"
            }
            $("#tbody").html(s1);
            $("#current-page").html("第"+pageinfo.pageNum+"页");
            if(!pageinfo.hasPreviousPage){
                $("#first").attr("class","disabled");
                $("#pre").attr("class","disabled");
                $("#first").html("<a href=\"javascript:void(0);\">首页</a>");
                $("#pre").html("<a href=\"javascript:void(0);\" >上一页</a>");
            }else{
                $("#first").removeAttr("class","disabled");
                $("#pre").removeAttr("class","disabled");
                $("#first").html("<a href=\"javascript:void(0);\" onclick=\"getinfo(1)\">首页</a>");
                $("#pre").html("<a href=\"javascript:void(0);\" onclick=\"getinfo("+pageinfo.prePageNum+")\">上一页</a>");
            }
            if(!pageinfo.hasNextPage){
                $("#next").attr("class","disabled");
                $("#last").attr("class","disabled");
                $("#next").html("<a href=\"javascript:void(0);\">下一页</a>");
                $("#last").html("<a href=\"javascript:void(0);\" >尾页</a>");
            }else{
                $("#next").removeAttr("class","disabled");
                $("#last").removeAttr("class","disabled");
                $("#next").html("<a href=\"javascript:void(0);\" onclick=\"getinfo("+pageinfo.nextPageNum+")\">下一页</a>");
                $("#last").html("<a href=\"javascript:void(0);\" onclick=\"getinfo("+pageinfo.totalpage+")\">尾页</a>");
            }
            $("#total").html(pageinfo.totalpage)
        },
        datatype: "json"
    })
}

function transferto() {
    var tale=new $.tale();
    var pagenum=$("#pagenum").val();
    var totalpage=$("#total").html();
    if(pagenum<1||pagenum>totalpage||pagenum==''){
        tale.alertWarn("页码无效!");
        return;
    }
    getinfo(pagenum);
}